package main.canvas;

import main.utils.RiverConstants;

import java.awt.*;

public class RiverGrid extends CanvasComponent {
    private int columns;
    private int rows;
    private boolean isDebug = RiverConstants.DEBUG_MODE;

    public RiverGrid(int columns, int rows, int width, int height) {
        super();
        this.columns = columns;
        this.rows = rows;
        this.width = width;
        this.height = height;
    }

    @Override
    public void draw(Graphics2D g) {
        g.setColor(Color.blue);

        if (isDebug) {
            g.drawLine(getX(), 0, getX() + width, height);
            for (int i = 0; i <= columns; i++) {
                int x = getX() + width / columns * i;
                g.drawLine(x, 0, x, height);
            }
            for (int i = 0; i <= rows; i++) {
                int y = getY() + height / rows * i;
                g.drawLine(getX(), y, getX() + width, y);
            }
        }
    }

    public void add(int column, int row, CanvasComponent component) {
        component.setX(getX() + width / columns * column);
        component.setY(getY() + height / rows * row);
        component.setWidth(width / columns);
        component.setHeight(height / rows);
        getChildren().add(component);
    }

    public int getColumns() {
        return columns;
    }

    public void setColumns(int columns) {
        this.columns = columns;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }
}
